using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Data.SqlTypes;
using System.Text;

namespace Data_Access_Tier
{
	public class SYS_INFOData : DatabaseObjectBase
	{
		public SYS_INFOData()
		{
			Initialize(true);
		}
		public SYS_INFOData(Boolean newConnection)
		{
			Initialize(newConnection);
		}

		public Int32 SYS_INFO_Insert(String SysInfo_ID, String Application, String Version, Int32 Type, DateTime Created, String Description, Int32 Interface, String Guid_ID)
		{
			try
			{
				if (_dbconn.State != ConnectionState.Open)
					_dbconn.Open();
				_dbadapter.InsertCommand = new SqlCommand("SYS_INFO_Insert");
				_dbadapter.InsertCommand.CommandType = CommandType.StoredProcedure;
				_dbadapter.InsertCommand.Connection = _dbconn;
				_trans = _dbconn.BeginTransaction();
				_dbadapter.InsertCommand.Transaction = _trans;
				_dbadapter.InsertCommand.Parameters.Clear();
				_dbadapter.InsertCommand.Parameters.Add(new SqlParameter("@SysInfo_ID", SqlDbType.VarChar, 10));
				_dbadapter.InsertCommand.Parameters.Add(new SqlParameter("@Application", SqlDbType.VarChar, 50));
				_dbadapter.InsertCommand.Parameters.Add(new SqlParameter("@Version", SqlDbType.VarChar, 50));
				_dbadapter.InsertCommand.Parameters.Add(new SqlParameter("@Type", SqlDbType.Int));
				_dbadapter.InsertCommand.Parameters.Add(new SqlParameter("@Created", SqlDbType.DateTime));
				_dbadapter.InsertCommand.Parameters.Add(new SqlParameter("@Description", SqlDbType.NVarChar, 255));
				_dbadapter.InsertCommand.Parameters.Add(new SqlParameter("@Interface", SqlDbType.Int));
				_dbadapter.InsertCommand.Parameters.Add(new SqlParameter("@Guid_ID", SqlDbType.NVarChar, 255));
				_dbadapter.InsertCommand.Prepare();
				SqlString SysInfo_IDSQL = SysInfo_ID;
				_dbadapter.InsertCommand.Parameters["@SysInfo_ID"].Value = SysInfo_IDSQL;
				SqlString ApplicationSQL = Application;
				_dbadapter.InsertCommand.Parameters["@Application"].Value = ApplicationSQL;
				SqlString VersionSQL = Version;
				_dbadapter.InsertCommand.Parameters["@Version"].Value = VersionSQL;
				SqlInt32 TypeSQL = Type;
				_dbadapter.InsertCommand.Parameters["@Type"].Value = TypeSQL;
				SqlDateTime CreatedSQL = SqlDateTime.Null;
				if (Created > DateTime.MinValue)
				{
					try
					{
						CreatedSQL = Created;
					}
					catch (Exception eCreated)
					{
						String CreatedMessage = eCreated.Message;
						CreatedSQL = SqlDateTime.Null;
					}
				}
				_dbadapter.InsertCommand.Parameters["@Created"].Value = CreatedSQL;
				SqlString DescriptionSQL = Description;
				_dbadapter.InsertCommand.Parameters["@Description"].Value = DescriptionSQL;
				SqlInt32 InterfaceSQL = Interface;
				_dbadapter.InsertCommand.Parameters["@Interface"].Value = InterfaceSQL;
				SqlString Guid_IDSQL = Guid_ID;
				_dbadapter.InsertCommand.Parameters["@Guid_ID"].Value = Guid_IDSQL;
				Int32 returnvalue = Convert.ToInt32(_dbadapter.InsertCommand.ExecuteScalar());

				_trans.Commit();
				return returnvalue;
			}
			catch (SqlException e)
			{
				try
				{
					_trans.Rollback();
				}
				catch (SqlException ex)
				{
					throw new Exception("SQL Rollback Error: SYS_INFO_Insert: " + ex.Message, ex);
				}
				throw new Exception("SQL Error: SYS_INFO_Insert: " + e.Message, e);
			}
			finally
			{
				if (_dbadapter.InsertCommand != null)
					_dbadapter.InsertCommand.Dispose();
				CloseConnection();
			}
		}
		public Int32 SYS_INFO_Update(String SysInfo_ID, String Application, String Version, Int32 Type, DateTime Created, String Description, Int32 Interface, String Guid_ID)
		{
			try
			{
				if (_dbconn.State != ConnectionState.Open)
					_dbconn.Open();
				_dbadapter.UpdateCommand = new SqlCommand("SYS_INFO_Update");
				_dbadapter.UpdateCommand.CommandType = CommandType.StoredProcedure;
				_dbadapter.UpdateCommand.Connection = _dbconn;

				_trans = _dbconn.BeginTransaction();
				_dbadapter.UpdateCommand.Transaction = _trans;

				_dbadapter.UpdateCommand.Parameters.Clear();
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@SysInfo_ID", SqlDbType.VarChar, 10));
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@Application", SqlDbType.VarChar, 50));
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@Version", SqlDbType.VarChar, 50));
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@Type", SqlDbType.Int));
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@Created", SqlDbType.DateTime));
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@Description", SqlDbType.NVarChar, 255));
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@Interface", SqlDbType.Int));
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@Guid_ID", SqlDbType.NVarChar, 255));
				_dbadapter.UpdateCommand.Prepare();
				SqlString SysInfo_IDSQL = SysInfo_ID;
				_dbadapter.UpdateCommand.Parameters["@SysInfo_ID"].Value = SysInfo_IDSQL;
				SqlString ApplicationSQL = Application;
				_dbadapter.UpdateCommand.Parameters["@Application"].Value = ApplicationSQL;
				SqlString VersionSQL = Version;
				_dbadapter.UpdateCommand.Parameters["@Version"].Value = VersionSQL;
				SqlInt32 TypeSQL = Type;
				_dbadapter.UpdateCommand.Parameters["@Type"].Value = TypeSQL;
				SqlDateTime CreatedSQL = SqlDateTime.Null;
				if (Created > DateTime.MinValue)
				{
					try
					{
						CreatedSQL = Created;
					}
					catch (Exception eCreated)
					{
						String CreatedMessage = eCreated.Message;
						CreatedSQL = SqlDateTime.Null;
					}
				}
				_dbadapter.UpdateCommand.Parameters["@Created"].Value = CreatedSQL;
				SqlString DescriptionSQL = Description;
				_dbadapter.UpdateCommand.Parameters["@Description"].Value = DescriptionSQL;
				SqlInt32 InterfaceSQL = Interface;
				_dbadapter.UpdateCommand.Parameters["@Interface"].Value = InterfaceSQL;
				SqlString Guid_IDSQL = Guid_ID;
				_dbadapter.UpdateCommand.Parameters["@Guid_ID"].Value = Guid_IDSQL;
				Int32 returnvalue = Convert.ToInt32(_dbadapter.UpdateCommand.ExecuteScalar());

				_trans.Commit();
				return returnvalue;
			}
			catch (SqlException e)
			{
				try
				{
					_trans.Rollback();
				}
				catch (SqlException ex)
				{
					throw new Exception("SQL Rollback Error: SYS_INFO_Update: " + ex.Message, ex);
				}
				throw new Exception("SQL Error: SYS_INFO_Update: " + e.Message, e);
			}
			finally
			{
				if (_dbadapter.UpdateCommand != null)
					_dbadapter.UpdateCommand.Dispose();
				CloseConnection();
			}
		}
		public Int32 SYS_INFO_Disable(String SysInfo_ID, ref Boolean Enabled)
		{
			try
			{
				if (_dbconn.State != ConnectionState.Open)
					_dbconn.Open();
				_dbadapter.UpdateCommand = new SqlCommand("SYS_INFO_Disable");
				_dbadapter.UpdateCommand.CommandType = CommandType.StoredProcedure;
				_dbadapter.UpdateCommand.Connection = _dbconn;

				_trans = _dbconn.BeginTransaction();
				_dbadapter.UpdateCommand.Transaction = _trans;

				_dbadapter.UpdateCommand.Parameters.Clear();
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@SysInfo_ID", SqlDbType.VarChar, 10));
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@enabled", SqlDbType.Bit));
				_dbadapter.UpdateCommand.Prepare();
				SqlString SysInfo_IDSQL = SysInfo_ID;
				_dbadapter.UpdateCommand.Parameters["@SysInfo_ID"].Value = SysInfo_IDSQL;
				_dbadapter.UpdateCommand.Parameters["@enabled"].Direction = ParameterDirection.Output;
				Int32 returnvalue = Convert.ToInt32(_dbadapter.UpdateCommand.ExecuteScalar());

				_trans.Commit();
				return returnvalue;
			}
			catch (SqlException e)
			{
				try
				{
					_trans.Rollback();
				}
				catch (SqlException ex)
				{
					throw new Exception("SQL Rollback Error: SYS_INFO_Disable: " + ex.Message, ex);
				}
				throw new Exception("SQL Error: SYS_INFO_Disable: " + e.Message, e);
			}
			finally
			{
				if (_dbadapter.UpdateCommand != null)
					_dbadapter.UpdateCommand.Dispose();
				CloseConnection();
			}
		}
		public Int32 SYS_INFO_Delete(String SysInfo_ID)
		{
			try
			{
				if (_dbconn.State != ConnectionState.Open)
					_dbconn.Open();
				_dbadapter.DeleteCommand = new SqlCommand("SYS_INFO_Delete");
				_dbadapter.DeleteCommand.CommandType = CommandType.StoredProcedure;
				_dbadapter.DeleteCommand.Connection = _dbconn;

				_trans = _dbconn.BeginTransaction();
				_dbadapter.DeleteCommand.Transaction = _trans;

				_dbadapter.DeleteCommand.Parameters.Clear();
				_dbadapter.DeleteCommand.Parameters.Add(new SqlParameter("@SysInfo_ID", SqlDbType.VarChar, 10));
				_dbadapter.DeleteCommand.Prepare();
				SqlString SysInfo_IDSQL = SysInfo_ID;
				_dbadapter.DeleteCommand.Parameters["@SysInfo_ID"].Value = SysInfo_IDSQL;
				Int32 returnvalue = Convert.ToInt32(_dbadapter.DeleteCommand.ExecuteScalar());

				_trans.Commit();
				return returnvalue;
			}
			catch (SqlException e)
			{
				try
				{
					_trans.Rollback();
				}
				catch (SqlException ex)
				{
					throw new Exception("SQL Rollback Error: SYS_INFO_Delete: " + ex.Message, ex);
				}
				throw new Exception("SQL Error: SYS_INFO_Delete: " + e.Message, e);
			}
			finally
			{
				if (_dbadapter.DeleteCommand != null)
					_dbadapter.DeleteCommand.Dispose();
				CloseConnection();
			}
		}
		public Int32 SYS_INFO_Save(String SysInfo_ID, String Application, String Version, Int32 Type, DateTime Created, String Description, Int32 Interface, String Guid_ID)
		{
			try
			{
				if (_dbconn.State != ConnectionState.Open)
					_dbconn.Open();
				_dbadapter.UpdateCommand = new SqlCommand("SYS_INFO_Save");
				_dbadapter.UpdateCommand.CommandType = CommandType.StoredProcedure;
				_dbadapter.UpdateCommand.Connection = _dbconn;

				_trans = _dbconn.BeginTransaction();
				_dbadapter.UpdateCommand.Transaction = _trans;

				_dbadapter.UpdateCommand.Parameters.Clear();
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@SysInfo_ID", SqlDbType.VarChar, 10));
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@Application", SqlDbType.VarChar, 50));
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@Version", SqlDbType.VarChar, 50));
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@Type", SqlDbType.Int));
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@Created", SqlDbType.DateTime));
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@Description", SqlDbType.NVarChar, 255));
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@Interface", SqlDbType.Int));
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@Guid_ID", SqlDbType.NVarChar, 255));
				_dbadapter.UpdateCommand.Prepare();
				SqlString SysInfo_IDSQL = SysInfo_ID;
				_dbadapter.UpdateCommand.Parameters["@SysInfo_ID"].Value = SysInfo_IDSQL;
				SqlString ApplicationSQL = Application;
				_dbadapter.UpdateCommand.Parameters["@Application"].Value = ApplicationSQL;
				SqlString VersionSQL = Version;
				_dbadapter.UpdateCommand.Parameters["@Version"].Value = VersionSQL;
				SqlInt32 TypeSQL = Type;
				_dbadapter.UpdateCommand.Parameters["@Type"].Value = TypeSQL;
				SqlDateTime CreatedSQL = SqlDateTime.Null;
				if (Created > DateTime.MinValue)
				{
					try
					{
						CreatedSQL = Created;
					}
					catch (Exception eCreated)
					{
						String CreatedMessage = eCreated.Message;
						CreatedSQL = SqlDateTime.Null;
					}
				}
				_dbadapter.UpdateCommand.Parameters["@Created"].Value = CreatedSQL;
				SqlString DescriptionSQL = Description;
				_dbadapter.UpdateCommand.Parameters["@Description"].Value = DescriptionSQL;
				SqlInt32 InterfaceSQL = Interface;
				_dbadapter.UpdateCommand.Parameters["@Interface"].Value = InterfaceSQL;
				SqlString Guid_IDSQL = Guid_ID;
				_dbadapter.UpdateCommand.Parameters["@Guid_ID"].Value = Guid_IDSQL;
				Int32 returnvalue = Convert.ToInt32(_dbadapter.UpdateCommand.ExecuteScalar());

				_trans.Commit();
				return returnvalue;
			}
			catch (SqlException e)
			{
				try
				{
					_trans.Rollback();
				}
				catch (SqlException ex)
				{
					throw new Exception("SQL Rollback Error: SYS_INFO_Save: " + ex.Message, ex);
				}
				throw new Exception("SQL Error: SYS_INFO_Save: " + e.Message, e);
			}
			finally
			{
				if (_dbadapter.UpdateCommand != null)
					_dbadapter.UpdateCommand.Dispose();
				CloseConnection();
			}
		}
		public DataSet SYS_INFO_GetList()
		{
			try
			{
				if (_dbconn.State != ConnectionState.Open)
					_dbconn.Open();
				_dbadapter.SelectCommand = new SqlCommand("SYS_INFO_GetList");
				_dbadapter.SelectCommand.CommandType = CommandType.StoredProcedure;
				_dbadapter.SelectCommand.Connection = _dbconn;
				_dbadapter.SelectCommand.Parameters.Clear();
				_dbadapter.SelectCommand.Prepare();
				_dbadapter.Fill(_data);

				return _data;
			}
			catch (SqlException e)
			{
				throw new Exception("SQL Error: SYS_INFO_GetList: " + e.Message, e);
			}
			finally
			{
				if (_dbadapter.SelectCommand != null)
					_dbadapter.SelectCommand.Dispose();
				CloseConnection();
			}
		}
		public DataSet SYS_INFO_Get(String SysInfo_ID)
		{
			try
			{
				if (_dbconn.State != ConnectionState.Open)
					_dbconn.Open();
				_dbadapter.SelectCommand = new SqlCommand("SYS_INFO_Get");
				_dbadapter.SelectCommand.CommandType = CommandType.StoredProcedure;
				_dbadapter.SelectCommand.Connection = _dbconn;
				_dbadapter.SelectCommand.Parameters.Clear();
				_dbadapter.SelectCommand.Parameters.Add(new SqlParameter("@SysInfo_ID", SqlDbType.VarChar, 10));
				_dbadapter.SelectCommand.Prepare();
				SqlString SysInfo_IDSQL = SysInfo_ID;
				_dbadapter.SelectCommand.Parameters["@SysInfo_ID"].Value = SysInfo_IDSQL;
				_dbadapter.Fill(_data);

				return _data;
			}
			catch (SqlException e)
			{
				throw new Exception("SQL Error: SYS_INFO_Get: " + e.Message, e);
			}
			finally
			{
				if (_dbadapter.SelectCommand != null)
					_dbadapter.SelectCommand.Dispose();
				CloseConnection();
			}
		}
	}
}
